<html>
<head><meta charset="utf-8"><title>Conditional crate-type · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html">Conditional crate-type</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205279915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205279915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nam Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205279915">(Jul 28 2020 at 19:30)</a>:</h4>
<p>Hi, I have a Rust crate that I want to build as a "dylib" when a feature is present and as a "rlib" when the feature is not. Is there anyway I could achieve this using Cargo.toml or <a href="http://build.rs">build.rs</a>?</p>



<a name="205283510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205283510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205283510">(Jul 28 2020 at 20:01)</a>:</h4>
<p>What's the harm in building it as both all the time?</p>



<a name="205283614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205283614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205283614">(Jul 28 2020 at 20:02)</a>:</h4>
<p>Otherwise, it sounds like you should have crate A with the shared stuff, then crate B (and maybe C?) with the specific features applied (and no longer be features in the outer crates)</p>



<a name="205284109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205284109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nam Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205284109">(Jul 28 2020 at 20:07)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> : What you said makes perfect sense. It's just that I'm exploring the possibility of doing such a thing. It would be great if the crate can be built as a dll only when specified so.</p>



<a name="205299043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205299043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nam Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205299043">(Jul 28 2020 at 22:36)</a>:</h4>
<p>@Jake Goulding: Another approach would be to conditionally parse an entry inside Cargo.toml. But I'm not sure if that is supported.</p>



<a name="205303337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205303337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205303337">(Jul 28 2020 at 23:35)</a>:</h4>
<p>I've also needed this in the past, and Cargo should support this use case.</p>



<a name="205574025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Conditional%20crate-type/near/205574025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Conditional.20crate-type.html#205574025">(Jul 31 2020 at 09:41)</a>:</h4>
<p>I once looked into this for <a href="https://github.com/rust-lang/rust/issues/56443">https://github.com/rust-lang/rust/issues/56443</a>, no luck</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>